import java.util.Timer;
import java.util.TimerTask;

public class Demo {

    //定时器
    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("这是一个定时器!!");
            }
        },3000);

    }
    public static void main1(String[] args) {
        MyBlockingQueue que = new MyBlockingQueue();

        Thread thread1 = new Thread(()->{
            while (true) {
                try {
                    int val = que.take();
                    System.out.println("消费:"+ val);
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        thread1.start();

        Thread thread2 = new Thread(()->{
            int n = 0;
           while(true) {
               try {
                   que.put(n);
                   System.out.println("生产:"+n);
                   n++;
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
        thread2.start();
    }
}
